home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 May: Tool Chest / Dev.CD May 97 TC.toast / Sample Code / Processes / ProcDoggie 2.1b1 / UProcessLDEF.p < prev    next >
Encoding:
Text File  |  1997-03-20  |  7.6 KB  |  230 lines  |  [TEXT/CWIE]

  1. UNIT UProcessLDEF;
  2.  
  3. {-------------------------------------------------------------------------------
  4.     File:        ProcessLDEF.p
  5.  
  6.     Contains:    Process-list LDEF.
  7.  
  8.     Written by:    Forrest Tanaka
  9.  
  10.     Copyright:    © 1988-1997 by Apple Computer, Inc., all rights reserved.
  11.  
  12.     Change History (most recent first):
  13.  
  14.     You may incorporate this sample code into your applications without
  15.     restriction, though the sample code has been provided "AS IS" and the
  16.     responsibility for its operation is 100% yours.  However, what you are
  17.     not permitted to do is to redistribute the source as "DSC Sample Code"
  18.     after having made changes. If you're going to re-distribute the source,
  19.     we require that you make it clear in the source that the code was
  20.     descended from Apple Sample Code, but that you've made changes.
  21. --------------------------------------------------------------------------------
  22. #
  23. #    This LDEF is a simple replacement for the standard LDEF.  The only advantange
  24. #    this LDEF has over the standard LDEF is that it contains information specific
  25. #    to processes that aren’t displayed.  This is to make identifying processes in
  26. #    the Process List window easier.
  27. #
  28. #    Once the icon utilities are released to the developer community, this LDEF
  29. #    will be updated to display the icon of each process in the list.
  30. #
  31. -------------------------------------------------------------------------------}
  32. {[j=20/57/1$] Pasmat Options}
  33.  
  34.  
  35. INTERFACE
  36.  
  37.  
  38. (*******************************************************************************
  39. * Used Units
  40. *******************************************************************************)
  41.  
  42.     USES
  43.         Processes
  44.         ,Lists
  45.         ;
  46.  
  47. (*******************************************************************************
  48. * Types
  49. *******************************************************************************)
  50.  
  51.     TYPE
  52.         ProcessListInfoRec = RECORD
  53.             processName:    Str255;               {Process’s name}
  54.             serialNumber:   ProcessSerialNumber  {Process’s serial number}
  55.         END;
  56.         ProcessListInfoPtr = ^ProcessListInfoRec;
  57.  
  58.  
  59. (*******************************************************************************
  60. * ProcessList - Entry point to the List Definition Procedure
  61. *
  62. * This is the entry point to the custom list defproc used in ProcDoggie.  ProcDoggie
  63. * actually uses the world's simplest LDEF.  All that LDEF does is call through
  64. * the ListRec's refCon field.  So we jam the address of ProcessListLDEF into that
  65. * field and, voila, we don't have to have a separate LDEF and we can debug
  66. * our LDEF in a high-level debugger.  It's kinda like the classic "6 byte LDEF"
  67. * trick, except we don't have to worry about cache flushing.
  68. *******************************************************************************)
  69.  
  70.     PROCEDURE ProcessListLDEF (message:    Integer;
  71.                            selectCell: Boolean;
  72.                            VAR cellRect:   Rect;
  73.                            theCell:    Cell;
  74.                            dataOffset: Integer;
  75.                            dataLength: Integer;
  76.                            theList:    ListHandle);
  77.  
  78.  
  79. IMPLEMENTATION
  80.  
  81.     USES
  82.         Script
  83.         ,TextEdit
  84.         ,LowMem
  85.         ,ToolUtils
  86.         ;
  87.  
  88.     CONST
  89.         kCellMargin = 3; {Margin between list contents and list edge in pixels}
  90.  
  91.  
  92.     {$S Main}
  93.     (*******************************************************************************
  94.     * Private: HilightCell - Hilight the specified cell
  95.     *
  96.     * This routine hilights the cell whose rectangle is cellRect.  I also clear the
  97.     * hilight bit of the HiliteMode low-memory global.  If this is running on a
  98.     * Color QuickDraw machine, then background hilighting is done instead of
  99.     * the usual inversion.
  100.     *******************************************************************************)
  101.  
  102.     PROCEDURE HilightCell (cellRect: Rect);
  103.  
  104.     VAR
  105.         hiliteModeValue:    ByteParameter;
  106.         
  107.     BEGIN
  108.         (* Do the fancy, new kind of hilighting on a Color QuickDraw Mac *)
  109.         hiliteModeValue := LMGetHiliteMode;
  110.         BitClr(Ptr(@hiliteModeValue), pHiliteBit);
  111.         LMSetHiliteMode(hiliteModeValue);
  112.  
  113.         (* Now, hilight the cell *)
  114.         InvertRect (cellRect)
  115.     END;
  116.  
  117.  
  118.     {$S Main}
  119.     (*******************************************************************************
  120.     * Private: DrawCell - Draw the contents of the specified cell
  121.     *
  122.     * This routine draws the contents of the cell specified by theCell into it’s
  123.     * rectangle, which is specified by cellRect.  In case the font is too large for
  124.     * the cell rectangle, I set the clip region to cellRect before drawing the cell
  125.     * text, then set it back to what it was afterwards.
  126.     *
  127.     * If selected is TRUE, then theCell is selected.  In that case, my HilightCell
  128.     * routine is called to hilight the cell.
  129.     *
  130.     * The list that this all takes place in is specified by theList.
  131.     *******************************************************************************)
  132.  
  133.     PROCEDURE DrawCell (cellRect:   Rect;
  134.                         theCell:    Cell;
  135.                         selected:   Boolean;
  136.                         theList:    ListHandle;
  137.                         dataOffset: Integer);
  138.  
  139.         VAR
  140.             cellInfo:   ProcessListInfoRec; {Information for cell to be drawn}
  141.             currClip:   RgnHandle;          {Handle to the current clip region}
  142.             currPen:    PenState;           {Current pen characteristics}
  143.             currFont:   FontInfo;           {Current font characteristics}
  144.             dataLen:    Integer;            {Length of cell data in bytes}
  145.             marginRect: Rect;               {Rect that process name is drawn into}
  146.             alignment:  Integer;            {Alignment of process name text}
  147.             spareSpace: Integer;            {marginRect width - text width}
  148.  
  149.     BEGIN
  150.         {$unused dataOffset}
  151.         
  152.         (* Save the current pen state and set the default pen characteristics *)
  153.         GetPenState ((*<*)currPen);
  154.         PenNormal;
  155.  
  156.         (* Save the current clip region and set it to cellRect *)
  157.         currClip := NewRgn;
  158.         GetClip ((*<*)currClip);
  159.         ClipRect (cellRect);
  160.  
  161.         (* Will draw text into the cell rect with a margin on left and right *)
  162.         marginRect := cellRect;
  163.         InsetRect ((*◊*)marginRect, kCellMargin, 0);
  164.  
  165.         (* Get the information for the specified cell *)
  166.         dataLen := SIZEOF (ProcessListInfoRec);
  167.         LGetCell ((*<*)Ptr(@cellInfo), (*◊*)dataLen, theCell, theList);
  168.  
  169.         (* To find where to draw the cell’s text, get current font information *)
  170.         GetFontInfo ((*<*)currFont);
  171.  
  172.         (* Position the pen for drawing the text *)
  173.         MoveTo (marginRect.left, marginRect.top + currFont.ascent);
  174.  
  175.         (* Determine whether system script is left-to-right or right-to-left *)
  176.         IF GetSysDirection = 0 THEN
  177.             alignment := teFlushLeft
  178.         ELSE
  179.             alignment := teFlushRight;
  180.  
  181.         (* Adjust the pen for right-aligned text if script is right-to-left *)
  182.         IF alignment = teFlushRight THEN
  183.             BEGIN
  184.                 spareSpace := marginRect.right - marginRect.left -
  185.                         StringWidth (cellInfo.processName);
  186.                 Move (spareSpace, 0);
  187.             END;
  188.  
  189.         (* Draw the cell’s contents *)
  190.         EraseRect (cellRect);
  191.         DrawString (cellInfo.processName);
  192.  
  193.         (* If the cell is selected, hilight it *)
  194.         IF selected THEN
  195.             HilightCell (cellRect);
  196.  
  197.         (* Restore the current clip region and pen *)
  198.         SetClip (currClip);
  199.         DisposeRgn (currClip);
  200.         SetPenState (currPen);
  201.     END;
  202.  
  203.  
  204.     {$S Main}
  205.     (*******************************************************************************
  206.     * Public: ProcessList
  207.     *
  208.     * Here’s the entry point to my custom LDEF.  Yup.
  209.     *******************************************************************************)
  210.  
  211.     PROCEDURE ProcessListLDEF (message:    Integer;
  212.                            selectCell: Boolean;
  213.                            VAR cellRect:   Rect;
  214.                            theCell:    Cell;
  215.                            dataOffset: Integer;
  216.                            dataLength: Integer;
  217.                            theList:    ListHandle);
  218.  
  219.     BEGIN
  220.         IF message = lDrawMsg THEN
  221.             BEGIN
  222.                 IF dataLength > 0 THEN
  223.                     DrawCell (cellRect, theCell, selectCell, theList, dataOffset)
  224.             END
  225.         ELSE IF message = lHiliteMsg THEN
  226.             HilightCell (cellRect)
  227.     END;
  228.  
  229. END.
  230.